//
//  CommentBottomCell.m
//  sensen_ios
//
//  Created by mc on 16/3/4.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "CommentBottomCell.h"

@interface CommentBottomCell ()
{
    UIImageView *_favourImgView; // 点赞图片
    UILabel *_favourLabel; // 点赞数量
    
    UIImageView *_commentImgView; // 回复图片
    UILabel *_commentLabel; // 回复数量
    
}

@end

@implementation CommentBottomCell

+(instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString * cellIdentifier = @"CommentBottomCell";
    CommentBottomCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell ==nil) {
        cell = [[self alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
    
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        
        
    }
    return self;
}
- (void)setupSubViews{
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }

    // 回复
    _commentImgView = [[UIImageView alloc] init];
    _commentImgView.image = [UIImage imageNamed:@"论坛_进入论坛_评论"];
    [self.contentView addSubview:_commentImgView];
    _commentLabel = [[UILabel alloc] init];
    _commentLabel.font = FONT(13);
    _commentLabel.textColor = [UIColor darkGrayColor];
    _commentLabel.text = _postModel.replies;
    _commentLabel.adjustsFontSizeToFitWidth = YES;
    [self.contentView addSubview:_commentLabel];
    
    
    
    
    // 点赞
    _favourImgView = [[UIImageView alloc] init];
    _favourImgView.image = [UIImage imageNamed:@"论坛_进入论坛_赞"];
    [self.contentView addSubview:_favourImgView];
    _favourLabel = [[UILabel alloc] init];
    _favourLabel.font = FONT(13);
    _favourLabel.text = _postModel.likes;
    _favourLabel.textColor = [UIColor darkGrayColor];
    _favourLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_favourLabel];
    
    
    CGFloat width1 =  [_postModel.replies getSizeOfString:13].width;
    CGFloat width2 =  [_postModel.likes  getSizeOfString:13].width;
    
    [_commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.right.equalTo(self.contentView).offset(-10);
        make.size.mas_equalTo(CGSizeMake(width1 + 5, 20));

    }];
    [_commentImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.right.equalTo(_commentLabel.mas_left).offset(-5);
        make.size.mas_equalTo(CGSizeMake(20, 20));

    }];
    [_favourLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.right.equalTo(_commentImgView.mas_left).offset(0);
        make.size.mas_equalTo(CGSizeMake(width2 + 5, 20));
    }];
    [_favourImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.right.equalTo(_favourLabel.mas_left).offset(-5);
        make.size.mas_equalTo(CGSizeMake(20, 20));

    }];
}


- (void)setPostModel:(PostModel *)postModel{
    _postModel = postModel;
    [self setupSubViews];
}


@end
